package com.atguigu.springcloud.service.impl;

import com.atguigu.springcloud.service.IMessageProvider;

import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

// @Service 这里的service接口不再和dao打交道，而是作为消息生成者与rabbitmq绑定，故不用该注解
@EnableBinding(Source.class)  //定义消息的推送管道 output
public class IMessageProviderImpl implements IMessageProvider {

    @Resource
    private MessageChannel output; //消息发送管道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        System.out.println("我是消息发送者，发送消息："+serial);
        output.send(MessageBuilder.withPayload(serial).build());

        return "我是消息发送者，发送消息："+serial;
    }
}
